<style>
    label.red-start:before {
        content: '* ';
        color: red;
    }
    .layui-form-label{width:65px}
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form id="addFrm" class="layui-form" action="" lay-filter="component-form-group">
                <input type="hidden" name="id" value="<?= !empty($editData['id']) ? $editData['id'] : 0; ?>">
                <input type="hidden" name="set_day" value="<?= !empty($editData['set_day']) ? $editData['set_day'] : $set_day; ?>">
                <input type="hidden" name="set_id" value="<?= !empty($editData['set_id']) ? $editData['set_id'] : $set_id; ?>">
                <div class="layui-form-item">
                    <label class="layui-form-label">订单类型</label>
                    <div class="layui-input-inline">
                        <select name="type_id">
                            <option value="">请选择</option>
                            <?php foreach ($type as $k => $v) { ?>
                                <option value="<?= $k ?>"<?= !empty($editData["type_id"]) && $editData["type_id"] == $k ? " selected" : "" ?>><?= $v["name"] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                    <label class="layui-form-label">订单日期</label>
                    <div class="layui-input-inline">
                        <input type="text" name="order_date" id="order_date" value="<?= !empty($editData['order_date']) ? date("Y-m-d", $editData['order_date']) : date("Y-m-d"); ?>" autocomplete="off" placeholder="" class="layui-input">
                    </div>
                    <label class="layui-form-label">订单号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="order_no" value="<?= !empty($editData['order_no']) ? $editData['order_no'] : $order_no; ?>" autocomplete="off" placeholder="" readonly="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">

                    <label class="layui-form-label">客户</label>
                    <div class="layui-input-inline" style="width:485px">
                        <select name="kehu_custom_id" id="kehu_custom_id" lay-filter="kehu_custom_id" lay-search>
                            <option value="">请选择</option>
                            <?php foreach ($kehu as $k => $v) { ?>
                                <option value="<?= $v["id"] ?>"<?= !empty($editData["kehu_custom_id"]) && $editData["kehu_custom_id"] == $v["id"] ? " selected" : "" ?>><?= $v["cmp_bf"] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">提货地</label>
                    <div class="layui-input-inline" style="width:485px">
                        <select name="org_id" lay-filter="org_id" lay-search>
                            <option value="">请选择</option>
                            <option value="-1">+新增地址</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item" id="org_address_id" style="display: none">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-inline">
                        <select name="org_province_id" lay-filter="org_province_id" lay-search>
                            <option value="">州</option>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="display: none">
                        <select name="org_city_id" lay-filter="org_city_id">
                            <option value="">城市</option>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="display: none">
                        <select name="org_district_id" lay-filter="org_district_id">
                            <option value="">区县</option>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="width:285px">
                        <input type="text" name="org_address" value="<?= !empty($editData['org_address']) ? $editData['org_address'] : ""; ?>" autocomplete="off" placeholder="具体地址" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">送货地</label>
                    <div class="layui-input-inline" style="width:485px">
                        <select name="dest_id" lay-filter="dest_id" lay-search>
                            <option value="">请选择</option>
                            <option value="-1">+新增地址</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item" id="dest_address_id" style="display: none">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-inline">
                        <select name="dest_province_id" lay-filter="dest_province_id" lay-search>
                            <option value="">州</option>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="display: none">
                        <select name="dest_city_id" lay-filter="dest_city_id">
                            <option value="">城市</option>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="display: none">
                        <select name="dest_district_id" lay-filter="dest_district_id">
                            <option value="">区县</option>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="width:285px">
                        <input type="text" name="dest_address" value="<?= !empty($editData['dest_address']) ? $editData['dest_address'] : ""; ?>" autocomplete="off" placeholder="具体地址" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">货物名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="goods_name" value="<?= !empty($editData['goods_name']) ? $editData['goods_name'] : ""; ?>" autocomplete="off" placeholder="" class="layui-input">
                    </div>
                    <label class="layui-form-label">件数</label>
                    <div class="layui-input-inline">
                        <input type="text" name="num" value="<?= !empty($editData['num']) ? $editData['num'] : ""; ?>" autocomplete="off" placeholder="" class="layui-input">
                    </div>
                    <label class="layui-form-label">重量(吨)</label>
                    <div class="layui-input-inline">
                        <input type="text" name="weight" value="<?= !empty($editData['weight']) ? $editData['weight'] : ""; ?>" autocomplete="off" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">箱号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="xianghao" value="<?= !empty($editData['xianghao']) ? $editData['xianghao'] : ""; ?>" autocomplete="off" placeholder="请输入箱号1" class="layui-input">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" name="xianghao2" value="<?= !empty($editData['xianghao2']) ? $editData['xianghao2'] : ""; ?>" autocomplete="off" placeholder="请输入箱号2" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">备注/要求</label>
                    <div class="layui-input-inline">
                        <textarea name="remark" placeholder="" class="layui-textarea" style="width:485px"><?= !empty($editData['remark']) ? $editData['remark'] : "" ?></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn customize" lay-filter="formDemo" id="submitBtn">确定提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="<?= PUBLIC_URL . "/admin/js/order/cityClass.js?" . rand() ?>"></script>
<script>
    var doAddUrl = "<?= $doAddUrl ?>";
    var getCustomAddressUrl = "<?= $this->projectSet["url"]["getCustomAddress"] ?>";
    var getProvinceUrl = "<?= $this->projectSet["url"]["getProvince"] ?>";
    var getCityUrl = "<?= $this->projectSet["url"]["getCity"] ?>";
    var getDistrictUrl = "<?= $this->projectSet["url"]["getDistrict"] ?>";
</script>
<script src="<?= PUBLIC_URL . "/" . $this->projectSet["file"]["js"] . "/add.js?" . rand() ?>"></script>
<script>
    layui.use(['laypage', 'layer', 'form', 'element', 'laydate'], function () {
        var laypage = layui.laypage,
                frm = layui.form,
                layer = layui.layer,
                element = layui.element,
                laydate = layui.laydate;

        laydate.render({
            elem: '#order_date' //指定元素
                    //type: "datetime"
                    //range: true
        });

        frm.on('select(kehu_custom_id)', function (data) {
            changeKehuCustom(data.value, frm);
            $("#org_address_id").hide();
            $("#dest_address_id").hide();
            console.log('选中的值：', data.value);
            console.log('选中的文本：', data.elem[data.elem.selectedIndex].text);
        });

        frm.on('select(org_id)', function (data) {
            if (data.value == "-1") {
                $("#org_address_id").show();
            } else {
                $("#org_address_id").hide();
            }
        });
        frm.on('select(dest_id)', function (data) {
            if (data.value == "-1") {
                $("#dest_address_id").show();
            } else {
                $("#dest_address_id").hide();
            }
        });

        getOrg(<?= !empty($editData['kehu_custom_id']) ? $editData['kehu_custom_id'] : 0; ?>,<?= !empty($editData['org_id']) ? $editData['org_id'] : 0; ?>, frm);
        getDest(<?= !empty($editData['kehu_custom_id']) ? $editData['kehu_custom_id'] : 0; ?>,<?= !empty($editData['dest_id']) ? $editData['dest_id'] : 0; ?>, frm);

        frm.on('select(org_province_id)', function (data) {
            changeOrgProvince(data.value, frm);
        });
        frm.on('select(org_city_id)', function (data) {
            changeOrgCity(data.value, frm);
        });
        frm.on('select(dest_province_id)', function (data) {
            changeDestProvince(data.value, frm);
        });
        frm.on('select(dest_city_id)', function (data) {
            changeDestCity(data.value, frm);
        });

        getOrgProvince(<?= !empty($editData['org_province_id']) ? $editData['org_province_id'] : 0; ?>, frm);
        getOrgCity(<?= !empty($editData['org_province_id']) ? $editData['org_province_id'] : 0; ?>,<?= !empty($editData['org_city_id']) ? $editData['org_city_id'] : 0; ?>, frm);
        getOrgDistrict(<?= !empty($editData['org_city_id']) ? $editData['org_city_id'] : 0; ?>, <?= !empty($editData['org_district_id']) ? $editData['org_district_id'] : 0; ?>, frm);

        getDestProvince(<?= !empty($editData['dest_province_id']) ? $editData['dest_province_id'] : 0; ?>, frm);
        getDestCity(<?= !empty($editData['dest_province_id']) ? $editData['dest_province_id'] : 0; ?>,<?= !empty($editData['dest_city_id']) ? $editData['dest_city_id'] : 0; ?>, frm);
        getDestDistrict(<?= !empty($editData['dest_city_id']) ? $editData['dest_city_id'] : 0; ?>, <?= !empty($editData['dest_district_id']) ? $editData['dest_district_id'] : 0; ?>, frm);

//        $('#kehu_custom_id').next().find('input').on('input', function (e) {
//            var searchValue = this.value.toLowerCase().trim();
//            var selectElem = $('#kehu_custom_id')[0];
//            var options = selectElem.options;
//
//            if (searchValue === '') {
//                // 清空搜索时显示所有选项
//                for (var i = 0; i < options.length; i++) {
//                    options[i].style.display = '';
//                }
//                return;
//            }
//
//            // 遍历选项进行匹配
//            for (var i = 0; i < options.length; i++) {
//                var option = options[i];
//                var optionText = option.textContent || option.innerText;
//
//                if (optionText.toLowerCase().indexOf(searchValue) > -1) {
//                    option.style.display = '';
//                } else {
//                    option.style.display = 'none';
//                }
//            }
//        });

        // 监听选择事件
//        frm.on('select(kehu_custom_id)', function (data) {
//            console.log('选中的值：', data.value);
//            console.log('选中的文本：', data.elem[data.elem.selectedIndex].text);
//        });

    });
</script>
